from socket import *


"""




"""


class Server:
    def __init__(self):
        self.port = 9992
        self.buffersize = 1024
        self.clients = []        
        #self.dataqueue = []
        self.sock = socket(AF_INET, SOCK_DGRAM)
        self.sock.bind(("127.0.0.1",port))
        self.sock.setblocking(0)
        
    def send(self, data, clientid):
        self.sendto(data, self.clients[clientid])
        
    def getdata(self):
        datalist = []
        data, addr = None, None
        try:
            data, addr = self.sock.recvfrom(102)
            while data:
                datalist.append((data, addr))
                try:
                    data, addr = self.sock.recvfrom(self.buffersize)
                except:
                    data, addr = None, None
        except:
            pass
        return datalist
        
    def addclient(self, addr, port):
        self.clients.append((addr, port))

mysock=socket(AF_INET, SOCK_DGRAM)
mysock.bind(("127.0.0.1",9992))
mysock.setblocking(0)
last=0
while 1:
    raw_input("> ")
    datalist = []
    try:
        data, addr = mysock.recvfrom(1024)
    except:
        data, addr = None, None
    #print ":"+data+":"
    while data:
        datalist.append((data, addr))
        try:
            data, addr = mysock.recvfrom(1024)
        except:
            data, addr = None, None
    for data, addr in datalist:
        print addr[0]+": "+data